

import { _decorator, Component, Node, director, sys, view, ResolutionPolicy } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('GameManager')
export default class GameManager {
    private static _instance: GameManager | null = null;
    _curScene: string = "";//当前场景
    _lastScene: string = "";//上一场景
    _nextScene: string = ""; //下一场景
    _guideName: string = "";
    debugModel: boolean = false; //调试模式
    debugRewardAd: boolean = false;// 直接显示激励广告
    _publishPackage: boolean = true;

    difficult: number = 1;//游戏难度
    
    public setCurScene(sceneName: string) {
        this._curScene = sceneName;
    }
    public getCurScene() {
        return this._curScene;
    }

    // 获取上一场景
    public getLastScene() {
        return this._lastScene;
    }

    //获取下一场景
    public getNextScene() {
        return this._nextScene;
    }

    // 加载新场景
    public loadSceneByLoading(sceneName: string) {
        if ((!this.debugModel) && (this._nextScene == sceneName)) {
            return;
        }

        this._lastScene = this._curScene;
        this._nextScene = sceneName;

        // cc.director.getActionManager().pauseAllRunningActions();
        // cc.director.getActionManager().removeAllActions();
        director.loadScene("loadingScene");
    }
    // 随机整数,不包括max
    public randomInt = function (min, max) {
        let num = Math.floor(Math.random() * (max - min)) + min;
        // cc.log("randomInt min = " + min + " , max = " + max + " , num = " + num);
        return num;
    };
    // 获取当前日期
    public getCurDay() {
        let curDate = new Date();
        let day = curDate.getDate();
        return day;
    }
    // 适配
    public adaptation() {
        let size = view.getFrameSize();
        //let size = view.getVisibleSize();
        let num = size.width / size.height;
        if (num < 0.667) {
            view.setDesignResolutionSize(640, 960, ResolutionPolicy.FIXED_WIDTH);
        } else {
            view.setDesignResolutionSize(960, 640, ResolutionPolicy.FIXED_HEIGHT);
        }
    }

    //1：竖屏 0:横屏
    public GetScreenOrientation()
    {
        let size = view.getFrameSize();
        //let size = view.getVisibleSize();
        if (size.width>size.height) {
            return 0;
        }else
        {
            return 1;
        }
    }

    public static get Instance() {
        return GameManager._instance || (GameManager._instance = new GameManager());
    }
}
